package 多线程.课后作业.M5;


/**
 * 5)、设计一个多线程的程序如下：设计一个火车售票模拟程序。假如火车站要有100张火车票要卖出，
 * 现在有5个售票点同时售票，用5个线程模拟这5个售票点的售票情况。
 */
public class Test implements Runnable {
    private int ticket = 100;

    public  void run() {
        while (true){
            if (this.ticket > 0) {
                System.out.println(Thread.currentThread().getName() + "\t\t买票--" + this.ticket--);
            }else {
                break;
            }
        }
    }

    public static void main(String[] args) {
        Runnable runnable = new Test();
        Thread t = new Thread(runnable, "窗口1");
        Thread q = new Thread(runnable, "窗口2");
        Thread b = new Thread(runnable, "窗口3");
        Thread u = new Thread(runnable, "窗口4");
        Thread p = new Thread(runnable, "窗口5");

        t.start();
        q.start();
        b.start();
        u.start();
        p.start();
    }
}
